<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //call判断类型
        var toString = Object.prototype.toString;
        toString.call(123); //"[object Number]"
        toString.call('abcdef'); //"[object String]"
        toString.call(true); //"[object Boolean]"
        toString.call([1, 2, 3, 4]); //"[object Array]"
        toString.call({ name: 'wenzi', age: 25 }); //"[object Object]"
        toString.call(function () { console.log('this is function'); }); //"[object Function]"
        toString.call(undefined); //"[object Undefined]"
        toString.call(null); //"[object Null]"
        toString.call(new Date()); //"[object Date]"
        toString.call(/^[a-zA-Z]{5,20}$/); //"[object RegExp]"
        toString.call(new Error()); //"[object Error]"

        //constructor判断类型
        var n=1;
        console.log(n.constructor);
        n='1';
        console.log(n.constructor);
        n=[1,2];
        console.log(n.constructor);
        n={ name: 'wenzi', age: 25 };
        console.log(n.constructor);
        n=new Date();
        console.log(n.constructor);
        // n=undefined;不能被检测出
        //n=null;不能被检测出

        //typeof判断类型
        console.log(typeof 1);
        console.log(typeof '1');
        console.log(typeof true);
        console.log(typeof [1, 2, 3, 4]);
        console.log(typeof { name: 'wenzi', age: 25 });
        console.log(typeof undefined);
        console.log(typeof new Date());
    </script>
</body>

</html>